package Java复习;

import java.util.Iterator;
import java.util.LinkedList;

class Student{
    private String name;
    private int sorce;
    public Student(String name, int sorce) {
        this.name = name;
        this.sorce = sorce;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSorce() {
        return sorce;
    }

    public void setSorce(int sorce) {
        this.sorce = sorce;
    }
    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", sorce=" + sorce +
                '}';
    }
}
public class Num2 {
    public static void main(String[] args) {
        Student s1 = new Student("刘德华", 90);
        Student s2 = new Student("张学友", 80);
        Student s3 = new Student("刘杰", 65);
        Student s4 = new Student("章子怡", 100);
        Student s5 = new Student("周迅", 6);
        LinkedList<Student> list = new LinkedList<Student>();
        int flag = -1;
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);
        System.out.println("集合当中有" + list.size() + "个对象");
        for (Student student : list) {
            if ("刘杰".equals(student.getName())){
                flag = list.indexOf(student);
            }
        }
        if (flag != -1){
            list.remove(flag);
            flag = -1;
        }
        Iterator<Student> iter = list.iterator();
        while (iter.hasNext()){
            Student student = iter.next();
            System.out.println(student.getName() + ": " + student.getSorce());
        }
        for (Student student : list) {
            if ("刘德华".equals(student.getName())){
                flag = list.indexOf(student);
            }
        }
        if (flag != -1){
            list.remove(flag);
            list.add(new Student("刘德华", 95));
        }
        System.out.println("不及格的为：");
        list.stream().filter(s -> s.getSorce()<60).forEach(s -> System.out.println(s.getName() + ": " + s.getSorce()));
    }
}
